#pragma once
#include "ctlutil.h"

class CMyPosPassThru :  public IMediaSeeking, public CMediaPosition
{
private:

	IPin *m_pPin;
	IPin *m_pPin2;
	
	LONGLONG m_rtStart, m_rtStop;
	bool m_bReset;
	CCritSec m_PositionLock;

private:


	HRESULT GetPeer(IMediaPosition **ppMP);
	HRESULT GetPeerSeeking(IMediaSeeking **ppMS);
	

public:

	CMyPosPassThru(const TCHAR *, LPUNKNOWN, HRESULT*, IPin *, IPin*);
	DECLARE_IUNKNOWN


	
	HRESULT GetMediaTime(LONGLONG *pStartTime,LONGLONG *pEndTime);
	HRESULT RegisterMediaTime(LONGLONG rtStart, LONGLONG rtEnd);
	HRESULT ResetMediaTime();
	HRESULT EOS();
	



	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid,void **ppv);

	// IMediaSeeking methods
	STDMETHODIMP GetCapabilities( DWORD * pCapabilities );
	STDMETHODIMP CheckCapabilities( DWORD * pCapabilities );
	STDMETHODIMP SetTimeFormat(const GUID * pFormat);
	STDMETHODIMP GetTimeFormat(GUID *pFormat);
	STDMETHODIMP IsUsingTimeFormat(const GUID * pFormat);
	STDMETHODIMP IsFormatSupported( const GUID * pFormat);
	STDMETHODIMP QueryPreferredFormat( GUID *pFormat);
	STDMETHODIMP ConvertTimeFormat(LONGLONG * pTarget, const GUID * pTargetFormat,LONGLONG    Source, const GUID * pSourceFormat );
	STDMETHODIMP SetPositions( LONGLONG * pCurrent, DWORD CurrentFlags, LONGLONG * pStop, DWORD StopFlags );
	
	STDMETHODIMP GetPositions( LONGLONG * pCurrent, LONGLONG * pStop );
	STDMETHODIMP GetCurrentPosition( LONGLONG * pCurrent );
	STDMETHODIMP GetStopPosition( LONGLONG * pStop );
	STDMETHODIMP SetRate( double dRate);
	STDMETHODIMP GetRate( double * pdRate);
	STDMETHODIMP GetDuration( LONGLONG *pDuration);
	STDMETHODIMP GetAvailable( LONGLONG *pEarliest, LONGLONG *pLatest );
	STDMETHODIMP GetPreroll( LONGLONG *pllPreroll );

	// IMediaPosition properties
	STDMETHODIMP get_Duration(REFTIME * plength);
	STDMETHODIMP put_CurrentPosition(REFTIME llTime);
	STDMETHODIMP get_StopTime(REFTIME * pllTime);
	STDMETHODIMP put_StopTime(REFTIME llTime);
	STDMETHODIMP get_PrerollTime(REFTIME * pllTime);
	STDMETHODIMP put_PrerollTime(REFTIME llTime);
	STDMETHODIMP get_Rate(double * pdRate);
	STDMETHODIMP put_Rate(double dRate);
	STDMETHODIMP get_CurrentPosition(REFTIME * pllTime);
	STDMETHODIMP CanSeekForward(LONG *pCanSeekForward);
	STDMETHODIMP CanSeekBackward(LONG *pCanSeekBackward);

private:
	HRESULT GetSeekingLongLong( HRESULT (__stdcall IMediaSeeking::*pMethod)( LONGLONG * ),LONGLONG * pll );


};
